home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / tree / tree.frm < prev    next >
Text File  |  1995-09-06  |  6KB  |  240 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Directory - Sizes"
  4.    ClientHeight    =   6600
  5.    ClientLeft      =   1725
  6.    ClientTop       =   1695
  7.    ClientWidth     =   7275
  8.    Height          =   7005
  9.    Icon            =   TREE.FRX:0000
  10.    Left            =   1665
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   6600
  13.    ScaleWidth      =   7275
  14.    Top             =   1350
  15.    Width           =   7395
  16.    Begin CommandButton Command1 
  17.       Caption         =   "Scan"
  18.       Height          =   315
  19.       Left            =   120
  20.       TabIndex        =   3
  21.       Top             =   180
  22.       Width           =   795
  23.    End
  24.    Begin Outline DirOutline 
  25.       FontBold        =   0   'False
  26.       FontItalic      =   0   'False
  27.       FontName        =   "Fixedsys"
  28.       FontSize        =   9
  29.       FontStrikethru  =   0   'False
  30.       FontUnderline   =   0   'False
  31.       Height          =   5955
  32.       Left            =   120
  33.       PictureClosed   =   TREE.FRX:0302
  34.       PictureLeaf     =   TREE.FRX:045C
  35.       PictureMinus    =   TREE.FRX:05B6
  36.       PictureOpen     =   TREE.FRX:0710
  37.       PicturePlus     =   TREE.FRX:086A
  38.       TabIndex        =   2
  39.       Top             =   540
  40.       Width           =   7035
  41.    End
  42.    Begin DriveListBox Drive1 
  43.       Height          =   315
  44.       Left            =   1620
  45.       TabIndex        =   1
  46.       Top             =   180
  47.       Width           =   5535
  48.    End
  49.    Begin Label Label1 
  50.       Caption         =   "Drive"
  51.       Height          =   255
  52.       Left            =   1080
  53.       TabIndex        =   0
  54.       Top             =   240
  55.       Width           =   495
  56.    End
  57. End
  58. Dim Anzahl As Integer
  59. Dim Terminate As Integer
  60.  
  61. Function AddAllInNextLevel (CurrentPath As String, Level As Integer) As Long
  62.     
  63.     Dim Count, D(), i, DirName  ' Declare variables.
  64.     Dim ATTR_Directory
  65.     Dim Total, GrandTotal, SubTotal As Long
  66.     Dim AnzahlNow As Integer
  67.     Dim Ausgabe As String
  68.  
  69.     Counter = 0
  70.     Count = 0
  71.     Total = 0
  72.     GrandTotal = 0
  73.     SubTotal = 0
  74.     ATTR_Directory = 16
  75.     ATTR_Normal = 0
  76.  
  77.     DirName = Dir(CurrentPath + "*.*", ATTR_Directory)' Get first directory name.
  78.  
  79.     'Iterate through PATH, caching all subdirectories in D()
  80.  
  81.     Do While DirName <> ""
  82.     If DirName <> "." And DirName <> ".." Then
  83.         If (GetAttr(CurrentPath + DirName) And ATTR_Directory) <> 0 Then
  84.         If (Count Mod 10) = 0 Then
  85.             ReDim Preserve D(Count + 10)    ' Resize the array.
  86.         End If
  87.         Count = Count + 1   ' Increment counter.
  88.         D(Count) = DirName
  89.  
  90.         End If
  91.     End If
  92.     DirName = Dir   ' Get another directory name.
  93.     Loop
  94.     
  95.     ' -> Gr÷▀e des aktuellen Verzeichnis bestimmen
  96.  
  97.     DirName = Dir(CurrentPath + "*.*", 0)' Get first directory name.
  98.     
  99.     On Error GoTo ErrorHandler
  100.  
  101.     Do While DirName <> ""
  102.      If (GetAttr(CurrentPath + DirName) And ATTR_Directory) = 0 Then
  103.            Total = Total + FileLen(CurrentPath + DirName)
  104.            Counter = Counter + 1
  105.            If Counter Mod 50 = 0 Then
  106.            Form1.Caption = "Scan: " + CurrentPath & "\ (" + Format(Total / 1024, "#######0") + ")"
  107.            End If
  108.        End If
  109.        DirName = Dir   ' Get another name.
  110.     Loop
  111.     
  112.     ' Now recursively iterate through each cached subdirectory.
  113.     
  114.     For i = 1 To Count
  115.        
  116.        DirOutline.AddItem D(i) ' Put name in list box.
  117.        Anzahl = Anzahl + 1
  118.        AnzahlNow = Anzahl
  119.        DirOutline.Expand(Anzahl) = True
  120.        DirOutline.Indent(Anzahl) = Level
  121.  
  122.        Form1.Caption = "Scan: " + CurrentPath & D(i) & "\ (" + Format(GrandTotal / 1024, "#######0") + ")"
  123.  
  124.     DoEvents
  125.     If Terminate Then
  126.        Exit Function
  127.     End If
  128.  
  129.        SubTotal = AddAllInNextLevel(CurrentPath & D(i) & "\", Level + 1)
  130.  
  131.  
  132.        GrandTotal = GrandTotal + SubTotal
  133.        
  134.        Ausgabe = Format(SubTotal / (1024), "######0 kB ")
  135.        Ausgabe = String$(12 - Len(Ausgabe), " ") & Ausgabe
  136.  
  137.        DirOutline.List(AnzahlNow) = Ausgabe + D(i)' Put name in list box.
  138.  
  139.  
  140.     Next i
  141.  
  142.     AddAllInNextLevel = GrandTotal + Total
  143.  
  144.     Exit Function
  145.  
  146. ErrorHandler:
  147.  
  148.     Message = "File : " + CurrentPath + DirName + " - Error : " + Error$
  149.     Erg = MsgBox(Message, 48, "FileLen-Error")
  150.  
  151.     Resume Next
  152. End Function
  153.  
  154. Sub Command1_Click ()
  155. ' hier wird alle Arbeit getan :
  156. '
  157. ' Anfange mit dem Root-Directory:
  158.  
  159.     If Terminate = False Then
  160.     Terminate = True
  161.     Exit Sub
  162.     End If
  163.  
  164.  
  165.     Dim Path As String
  166.     Dim Ausgabe As String
  167.     Dim Total As Long
  168.  
  169.     Dim Count, D(), i, DirName  ' Declare variables.
  170.  
  171.     DirOutline.Clear
  172.  
  173.     Path = Left(Drive1.Drive, 2) + "\"
  174.     Anzahl = 0
  175.  
  176.     Terminate = False
  177.  
  178.     Form1.Caption = "Scan: " + Path
  179.     
  180.     Command1.Caption = "STOP"
  181.     Refresh
  182.  
  183.     DirOutline.AddItem Path, 0   ' Put name in list box.
  184.     DirOutline.Expand(0) = True
  185.     Total = AddAllInNextLevel(Path, 1)
  186.  
  187.     If Terminate = True Then
  188.      DirOutline.Clear
  189.     End If
  190.  
  191.        
  192.     Ausgabe = Format(Total / (1024), "######0 kB ")
  193.     Ausgabe = String$(12 - Len(Ausgabe), " ") & Ausgabe
  194.  
  195.     DirOutline.List(0) = Ausgabe + Path' Put name in list box.
  196.     Terminate = True
  197.  
  198.     Command1.Caption = "SCAN"
  199.     Form1.Caption = "Directory - Sizes"
  200.  
  201. End Sub
  202.  
  203. Sub DirOutline_Click ()
  204.     If DirOutline.Expand(DirOutline.ListIndex) Then
  205.        DirOutline.Expand(DirOutline.ListIndex) = False
  206.     Else
  207.        DirOutline.Expand(DirOutline.ListIndex) = True
  208.     End If
  209.  
  210. End Sub
  211.  
  212. Sub Form_Load ()
  213.     Terminate = True
  214. End Sub
  215.  
  216. Sub Form_Resize ()
  217.     If Form1.WindowState = 1 Then
  218.     Exit Sub
  219.     End If
  220.  
  221.  
  222.     If Height < 4000 Then
  223.     Height = 4000
  224.     End If
  225.     If Width < 6000 Then
  226.     Width = 6000
  227.     End If
  228.  
  229.     DirOutline.Height = Height - 1000
  230.     DirOutline.Width = Width - 400
  231.     Drive1.Width = Width - 1900
  232.     Refresh
  233.  
  234. End Sub
  235.  
  236. Sub Form_Unload (Cancel As Integer)
  237.     End
  238. End Sub
  239.  
  240.